
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/16/2013 12:50:20
-- Generated from EDMX file: D:\Studying\Lessons\2013\Chu de nang cao trong CNPM\Bai Tap\Bai tap 5\0912200_0912198_BT5\Database\Film.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [FilmCinema];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_GalaxyLichChieuGalaxy]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[LichChieuGalaxies] DROP CONSTRAINT [FK_GalaxyLichChieuGalaxy];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Galaxies]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Galaxies];
GO
IF OBJECT_ID(N'[dbo].[MegaStars]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MegaStars];
GO
IF OBJECT_ID(N'[dbo].[LichChieuGalaxies]', 'U') IS NOT NULL
    DROP TABLE [dbo].[LichChieuGalaxies];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Galaxies'
CREATE TABLE [dbo].[Galaxies] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Ten] nvarchar(max)  NOT NULL,
    [Khoichieu] nvarchar(max)  NULL,
    [Theloai] nvarchar(max)  NULL,
    [Phienban] nvarchar(max)  NULL,
    [Nuocsanxuat] nvarchar(max)  NULL,
    [Cumrap] nvarchar(max)  NULL,
    [Mota] nvarchar(max)  NULL,
    [Url] nvarchar(max)  NOT NULL,
    [Trailer] nvarchar(max)  NULL,
    [Hinhanh] nvarchar(max)  NULL
);
GO

-- Creating table 'MegaStars'
CREATE TABLE [dbo].[MegaStars] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Ten] nvarchar(max)  NOT NULL,
    [Khoichieu] nvarchar(max)  NULL,
    [Theloai] nvarchar(max)  NULL,
    [Phienban] nvarchar(max)  NULL,
    [Nuocsanxuat] nvarchar(max)  NULL,
    [Cumrap] nvarchar(max)  NULL,
    [Mota] nvarchar(max)  NULL,
    [Url] nvarchar(max)  NOT NULL,
    [Trailer] nvarchar(max)  NULL,
    [Hinhanh] nvarchar(max)  NULL
);
GO

-- Creating table 'LichChieuGalaxies'
CREATE TABLE [dbo].[LichChieuGalaxies] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Ngaychieu] nvarchar(max)  NOT NULL,
    [Giochieu] nvarchar(max)  NOT NULL,
    [Phongchieu] nvarchar(max)  NOT NULL,
    [Rap] nvarchar(max)  NOT NULL,
    [GalaxyId] int  NOT NULL,
    [Url] nvarchar(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Galaxies'
ALTER TABLE [dbo].[Galaxies]
ADD CONSTRAINT [PK_Galaxies]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MegaStars'
ALTER TABLE [dbo].[MegaStars]
ADD CONSTRAINT [PK_MegaStars]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'LichChieuGalaxies'
ALTER TABLE [dbo].[LichChieuGalaxies]
ADD CONSTRAINT [PK_LichChieuGalaxies]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [GalaxyId] in table 'LichChieuGalaxies'
ALTER TABLE [dbo].[LichChieuGalaxies]
ADD CONSTRAINT [FK_GalaxyLichChieuGalaxy]
    FOREIGN KEY ([GalaxyId])
    REFERENCES [dbo].[Galaxies]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_GalaxyLichChieuGalaxy'
CREATE INDEX [IX_FK_GalaxyLichChieuGalaxy]
ON [dbo].[LichChieuGalaxies]
    ([GalaxyId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------